export default {
  data() {
    return {
      carllist: {}, //车子信息
      stiplist: [], //店铺信息
      carid: '', //车子id
      xedColorList: [], //颜色list
      colorpopup: false, //颜色弹框

      specifAll: {
        brandlist: [], //品牌
        Serieslist: [], //系列
        Configulist: [], //车子
      },
      list: [],
      carList: {
        car_Type_Id: 3841, //车图片--系列id
      },
      isIcon: false, //删除按钮显示
      currentIndex: 0,
      id: 0,
      editname: '删除',
      derfimg: true, //是否显示默认图
      pageindex: 1,
      noInformation: false, //暂无信息
      defaultImg: false, //判断是否显示 true 显示， false隐藏
      showPage: false
    }
  },
  created() {},
  onLoad(caridxix) {
    // 选择品牌，系列，车子
    uni.$on('womycarlist', data => {
      Object.assign(this.specifAll, data)
      this.carList.car_Type_Id = 3841
      // console.log(this.specifAll)
      if (this.specifAll.Serieslist.carTypeId !== undefined) {
        this.carList.car_Type_Id = this.specifAll.Serieslist.carTypeId //系列id
      }
      if (data.Configulist && data.pageFrom === 'womycarlist') {
        this.InsertMyCarEntity() //添加车单
      }
    })
    //车子id
    // this.carid = 'd2521cc3d4134cefbf831eda8359d2b5'
    this.GetMyCarList() //获取车单列表
  },
  onUnload() {
    uni.$off('womycarlist')
  },
  methods: {
    // 点击导航栏右侧
    onNavigationBarButtonTap(e) {
      /**
       * 向本地存储中设置selecerequirments的值，即启动标识；
       */
      uni.setStorage({
        key: 'selecerequirments',
        data: true,
      })
      uni.switchTab({
        url: '/pages/index/index'
      })
    },
    //添加车单
    async InsertMyCarEntity() {
      try {
        let data = {
          brand_Id: JSON.stringify(this.specifAll.brandlist.bid),
          brand_Name: this.specifAll.brandlist.brand,
          car_Type_Id: this.specifAll.Serieslist.carTypeId,
          car_Type_Name: this.specifAll.Serieslist.carTypeName,
          configuration_Id: this.specifAll.Configulist.id,
          configuration_Name: this.specifAll.Configulist.name
        }
        const res = await this.$api.commodity.InsertMyCarEntity(data)
        if (res.code === 200) {
          this.GetMyCarList() //获取车单
        }
        console.log('tj', res)
      } catch (e) {
        console.log(e)
      }
    },
    //获取车单
    async GetMyCarList() {
      try {
        let data = {
          'pageIndex': this.pageindex,
          'pageSize': 10
        }
        const res = await this.$api.commodity.GetMyCarList(data)
        //如果总条数为0，说明没有车单，必须跳转品牌，选择车
        if (res.data.total === 0) {
          // uni.navigateTo({
          // 	url: '/pages_common/chooseSpecifications/chooseSpecifications?type=120'
          // })
          this.defaultImg = false
        } else {
          this.list = res.data.list

          this.defaultImg = true
          this.GetCarLoanPaymentList(JSON.stringify(this.list[0].configuration_Id))

        }
        this.showPage = true
      } catch (e) {
        console.log(e)
      }
    },
    //获取价格，店铺等
    async GetCarLoanPaymentList(id) {
      try {
        let data = {
          'configuration_Id': id, //车辆ID
          'lon': 0, //经度
          'lat': 0 //纬度
        }
        const res = await this.$api.commodity.GetCarLoanPaymentList(data)
        if (res.data.id === null) {
          this.noInformation = false
        } else {
          this.noInformation = true
          this.carid = res.data.goods_Carsource_Id
          // 所有信息 店铺信息 颜色信息
          this.carllist = res.data
          this.stiplist = res.data.goodsCarSourceStoreDetailEntity
          this.xedColorList = this.filtercolor(res.data.colorList) //颜色
          this.xedColorList.forEach(item => {
            item.chekd = false
          })
        }
      } catch (e) {
        console.log(e)
      }
    },
    //图片报错
    imageError: function(e) {
      if (e.type === 'error') {
        // this.derfimg = false
        // <image src="https://files.yzsheng.com/client/comparison/images/che.png"></image>
      }
    },
    // 删除车单
    async delcars(e) {
      let data = {
        'id': e
      }
      const res = await this.$api.commodity.DeleteMyCar(data)
      this.GetMyCarList() //获取车单列表
      // this.editname = '完成'
    },
    //编辑
    async edit() {
      this.isIcon = !this.isIcon
      if (this.isIcon) {
        this.editname = '完成'
      } else {
        this.editname = '删除'
      }
    },
    //添加配置
    addConf() {
      uni.navigateTo({
        url: '/pages_common/chooseSpecifications/chooseSpecifications?type=120&pageFrom=womycarlist'
      })
    },
    //轮播定位
    swierChange(e) {
      // this.carid = e.target.currentItemId
      // this.GetCarLoanPaymentList(e.target.currentItemId) //获取价格，店铺等
      // console.log(e.target.currentItemId, 'sad')
      this.currentIndex = e.detail.current
    },
    trandstioncs(e) {
      console.log(e)
    },
    //分割颜色
    filtercolor(data) {
      data.forEach(item => {
        var arr = item.inColour.colorCoding.split('/')
        item.inColour.neiColor = arr
      })
      return data
    },
    // 颜色弹框
    colorClick() {
      this.colorpopup = true
    },
    //查看配置
    //跳转车型参数--未完成
    lookpeiclick(item) {
      this.carllist.carid = item.configuration_Id
      this.carllist.car_Type_Name = item.car_Type_Name
      this.carllist.configuration_Name = item.configuration_Name
      this.carllist.car_ImageList = [{
        image: 'https://files.yzsheng.com/goodimg/cartypeimg/' + item.car_Type_Id + '.png!indexaskprice'
      }]
      uni.navigateTo({
        url: '/pages_common/productDcarConfigs/productDcarConfigs?carsList=' + encodeURIComponent(JSON.stringify(
          this.carllist))
      })
    },
  }
}
